package com.homegoods.resource.pullDownMenuAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckedTextView;

import com.homegoods.resource.R;
import com.kedll.library.adapter.MyArrayAdapter;

/**
 * 交易类型选择菜单适配器
 *
 * @author QiQi
 * @date 16/6/21
 */
public class CheckedTextAdapter extends MyArrayAdapter {
    private int selectionIndex = 0;

    public CheckedTextAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.single_selecte_item, null);
        }

        final CheckedTextView checkedText = ViewHolder.getView(convertView, R.id.checkedText);

        if (selectionIndex == position) {
            checkedText.setChecked(true);
        } else {
            checkedText.setChecked(false);
        }

        String label = getItem(position).toString();
        checkedText.setText(label);

        return convertView;
    }

    public int getSelectionIndex() {
        return selectionIndex;
    }

    public void setSelectionIndex(int selectionIndex) {
        this.selectionIndex = selectionIndex;
        notifyDataSetChanged();
    }

}
